package com.dyness.poi;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.dyness.poi.level.City;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * @author gaohaiqing
 * @since 2024/1/4
 */
public class ExcelUtil {

    public String readAssetNcFileExcelUpload(@RequestParam("file") MultipartFile file) {
        ImportParams importParams = new ImportParams();
        // 数据处理
        importParams.setHeadRows(1);
        importParams.setTitleRows(0);
        // 需要验证
        importParams.setNeedVerfiy(false);
        Date date = new Date();
        try {
            ExcelImportResult<City> result =
                    ExcelImportUtil.importExcelMore(file.getInputStream(), City.class, importParams);
            List<City> cityList = result.getList();
            System.out.println(cityList.size() + "---总记录数据-------");
            int total = cityList.size();
            for (int i = 0; i < total; i++) {
                //得到对象
                City city = cityList.get(i);
                //进行业务处理

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ok";
    }
}